﻿using System;
using System.Diagnostics;
using System.Runtime.Remoting.Messaging;

namespace OperationPlugins
{
    /// <summary>
    /// Identifies an operation.
    /// </summary>
    [DebuggerDisplay("{_value}")]
    [Serializable]
    public sealed class OperationId : MarshalByRefObject, ILogicalThreadAffinative
    {
        private readonly string _value;

        internal OperationId()
        {
        }

        /// <summary>
        /// Initializes a new instance of the OperationId class.
        /// </summary>
        /// <param name="value">The value of OperationId</param>
        public OperationId(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            _value = value;
        }

        /// <summary>
        /// Gets the value of OperationId.
        /// </summary>
        public string Value
        {
            get { return _value; }
        }

        public override int GetHashCode()
        {
            if (this == Operations.Any)
            {
                return GetType().FullName.GetHashCode();
            }
            else
            {
                return _value.GetHashCode();
            }
        }

        public override bool Equals(object obj)
        {
            var other = obj as OperationId;
            return other != null && other.GetHashCode() == GetHashCode();
        }

    }
}